library("tidyverse")
library("ggpubr")
library("zoo")
setwd("/mnt/LocalData/behaviour/aDN/aDN_behaviour")
gg_color_hue <- function(n) {
hues = seq(15, 375, length = n + 1)
hcl(h = hues, l = 65, c = 100)[1:n]
}
gg_color_hue(2)
[1] "#F8766D" "#00BFC4"
genotypes <- read_tsv("../2019_03_06_Courtship/genotype.tsv",col_names = TRUE)
genotypes
# indices_list <- list.files("raw data/") %>% str_subset("_Indices.csv")
indices_list <- list.files("../2019_03_06_Courtship/",recursive = TRUE) %>% str_subset("_Indices.csv") %>% str_subset("Male")
all_indices <- tibble()
for (indices_file in indices_list) {
video_name <- indices_file %>% str_remove("/.*")
temp <- read_csv(paste0("../2019_03_06_Courtship/",indices_file))
temp <- temp %>%
mutate(video = video_name)
all_indices <- bind_rows(all_indices,temp)
}
all_indices
all_male_indices <- left_join(x = genotypes,y = all_indices,by=c("video"="video","fly_id"="FlyId"))
ggplot(all_male_indices,aes(x=genotype,y=CourtshipIndexWithFacing)) +
geom_boxplot()
p1 <- ggplot(all_male_indices,aes(x=genotype,y=CourtshipIndex)) +
geom_boxplot()
p2 <- ggplot(all_male_indices,aes(x=genotype,y=CourtshipIndexWithFacing)) +
geom_boxplot()
p3 <- ggplot(all_male_indices,aes(x=genotype,y=TotalCCI)) +
geom_boxplot()
p4 <- ggplot(all_male_indices,aes(x=genotype,y=TotalCCIwFacing)) +
geom_boxplot()
ggarrange(plotlist = list(p1,p2,p3,p4),
# labels = c("ApproachingIndex",
# "ContactIndex",
# "EncirclingIndex",
# "FacingIndex",
# "TurningIndex",
# "WingIndex"),
# hjust = 1,
ncol = 4,
nrow = 1)
p1 <- ggplot(all_male_indices,aes(x=genotype,y=ApproachingIndex)) +
geom_boxplot()
p2 <- ggplot(all_male_indices,aes(x=genotype,y=ContactIndex)) +
geom_boxplot()
p3 <- ggplot(all_male_indices,aes(x=genotype,y=EncirclingIndex)) +
geom_boxplot()
p4 <- ggplot(all_male_indices,aes(x=genotype,y=FacingIndex)) +
geom_boxplot()
p5 <- ggplot(all_male_indices,aes(x=genotype,y=TurningIndex)) +
geom_boxplot()
p6 <- ggplot(all_male_indices,aes(x=genotype,y=WingIndex)) +
geom_boxplot()
ggarrange(plotlist = list(p1,p2,p3,p4,p5,p6),
# labels = c("ApproachingIndex",
# "ContactIndex",
# "EncirclingIndex",
# "FacingIndex",
# "TurningIndex",
# "WingIndex"),
# hjust = 1,
ncol = 3,
nrow = 2)
p1 <- ggplot(all_male_indices,aes(x=genotype,y=CourtshipInitiation)) +
geom_boxplot()
p2 <- ggplot(all_male_indices,aes(x=genotype,y=CourtshipTermination)) +
geom_boxplot()
p3 <- ggplot(all_male_indices,aes(x=genotype,y=CourtshipDuration)) +
geom_boxplot()
ggarrange(plotlist = list(p1,p2,p3),
ncol = 3,
nrow = 1)
df <- all_male_indices %>%
select(genotype,CourtshipTermination) %>%
group_by(genotype) %>%
mutate(len=length(CourtshipTermination))
#ggplot(df,aes(x=CourtshipTermination,color=genotype)) + geom_step(aes(len=len,y=..y.. * len),stat="ecdf")
ggplot(df,aes(x=CourtshipTermination,color=genotype)) + geom_step(aes(y=..y..),stat="ecdf")
df <- all_male_indices %>%
select(genotype,CourtshipDuration) %>%
group_by(genotype) %>%
mutate(len=length(CourtshipDuration))
#ggplot(df,aes(x=CourtshipDuration,color=genotype)) + geom_step(aes(len=len,y=..y.. * len),stat="ecdf")
ggplot(df,aes(x=CourtshipDuration,color=genotype)) + geom_step(aes(y=..y..),stat="ecdf")
p1 <- ggplot(all_male_indices,aes(x=genotype,y=ApproachingBoutLength)) +
geom_boxplot()
p2 <- ggplot(all_male_indices,aes(x=genotype,y=ContactBoutLength)) +
geom_boxplot()
p3 <- ggplot(all_male_indices,aes(x=genotype,y=EncirclingBoutLength)) +
geom_boxplot()
p4 <- ggplot(all_male_indices,aes(x=genotype,y=FacingBoutLength)) +
geom_boxplot()
p5 <- ggplot(all_male_indices,aes(x=genotype,y=TurningBoutLength)) +
geom_boxplot()
p6 <- ggplot(all_male_indices,aes(x=genotype,y=WingBoutLength)) +
geom_boxplot()
p7 <- ggplot(all_male_indices,aes(x=genotype,y=ApproachingBoutInterval)) +
geom_boxplot()
p8 <- ggplot(all_male_indices,aes(x=genotype,y=ContactBoutInterval)) +
geom_boxplot()
p9 <- ggplot(all_male_indices,aes(x=genotype,y=EncirclingBoutInterval)) +
geom_boxplot()
p10 <- ggplot(all_male_indices,aes(x=genotype,y=FacingBoutInterval)) +
geom_boxplot()
p11 <- ggplot(all_male_indices,aes(x=genotype,y=TurningBoutInterval)) +
geom_boxplot()
p12 <- ggplot(all_male_indices,aes(x=genotype,y=WingBoutInterval)) +
geom_boxplot()
ggarrange(plotlist = list(p1,p2,p3,p4,p5,p6,
p7,p8,p9,p10,p11,p12),
# labels = c("ApproachingIndex",
# "ContactIndex",
# "EncirclingIndex",
# "FacingIndex",
# "TurningIndex",
# "WingIndex"),
# hjust = 1,
ncol = 6,
nrow = 2)
#all_rawdata <- full_join(x = all_rawdata, y = genotypes, by = c("FileName"="video","Id"="fly_id"))
all_rawdata <- all_rawdata %>%
full_join(x = all_rawdata, y = genotypes, by = c("FileName"="video","Id"="fly_id")) %>%
replace_na(list(genotype = "CS female"))
# sum(is.na(all_rawdata$genotype))
# summary(all_rawdata$genotype)
# unique(all_rawdata$genotype)
all_rawdata
# # Extract density data to average
# p <- ggplot_build(test_plot)
# ggplot(as.data.frame(p$data[[1]]), aes(x,y)) + geom_line()
# ggplot(as.data.frame(p$data[[2]]), aes(x,y)) + geom_line()
all_rawdata <- all_rawdata %>%
unite("unique_fly",FileName,Id, remove = FALSE) %>%
group_by(unique_fly) %>%
mutate(
Multitasking = (Approaching + Encircling + Contact + Turning + WingGesture),
MultitaskingWithFacing = (Approaching + Encircling + Facing + Contact + Turning + WingGesture),
Courtship = ifelse(Multitasking>=1, 1, 0),
CourtshipWithFacing = ifelse(MultitaskingWithFacing>=1, 1, 0),
MultitaskingWithCopulation = (Approaching + Encircling + Contact + Turning + WingGesture + Copulation),
MultitaskingWithCopulationWithFacing = (Approaching + Encircling + Facing + Contact + Turning + WingGesture + Copulation),
CourtshipAndCopulation = ifelse(MultitaskingWithCopulation>=1, 1, 0),
CourtshipAndCopulationWthFacing = ifelse(MultitaskingWithCopulationWithFacing>=1, 1, 0),
SmoothedCourtship = ifelse((rollmean(Courtship, 150, fill = c(0,0,0), align = c("left")))>0.5, 1, 0),
SmoothedCopulation = ifelse((rollmean(Copulation, 1250, fill = c(0,0,0), align = c("center")))>0.5, 1, 0),
SmoothedDistToOther = ifelse((rollmean(ifelse(dist_to_other__mm > 2, 1, 0), 250, fill = c(1,1,NA), align = c("center")))>0.5, 1, 0)
)
calculate_indices <- function(input,){
}